#!/usr/bin/env bash

source ./config/env.sh
clear



# copy 证书文件
for node_ip in ${NODE_IP}
do
    # copy ca 证书文件
    echo "=========================================== ${node_ip} ==========================================="
    ssh root@${node_ip} "test -e ${K8S_CA_DIR}/admin/ || mkdir -p ${K8S_CA_DIR}/admin/"
    scp ${K8S_CA_DIR}/admin/* root@${node_ip}:${K8S_CA_DIR}/admin/

    # copy flannel 证书文件
    ssh root@${node_ip} "test -e ${K8S_CA_DIR}/flannel || mkdir -p ${K8S_CA_DIR}/flannel"
    scp ${K8S_CA_DIR}/flannel/* root@${node_ip}:${K8S_CA_DIR}/flannel
    
done


# copy 解压需要的包
for node_ip in ${NODE_IP}
do
    echo "=========================================== ${node_ip} ==========================================="
    ssh root@${node_ip} "test -e ${K8S_BIN_DIR} || mkdir -p ${K8S_BIN_DIR}"

    # etcd 执行文件
    scp ${K8S_BIN_DIR}/etcd* root@${node_ip}:${K8S_BIN_DIR}

    # flannel 执行文件
    scp ${K8S_BIN_DIR}/{flanneld,mk-docker-opts.sh} root@${node_ip}:${K8S_BIN_DIR}

    # docker 执行文件
    scp ${K8S_DATA}/unpack/docker/docker/* root@${node_ip}:${K8S_BIN_DIR}

    # kubelet 等执行文件
    scp ${K8S_DATA}/unpack/kubernetes/server/bin/* root@${node_ip}:${K8S_BIN_DIR}

    # docker-compose 文件
    scp ${K8S_BIN_DIR}/docker-compose root@${node_ip}:${K8S_BIN_DIR}

    # 配置权限和环境变量
    ssh root@${node_ip} "sudo chmod +x ${K8S_BIN_DIR}/*"
    ssh root@${node_ip} "echo PATH=${K8S_BIN_DIR}:$PATH >> /etc/profile"
    ssh root@${node_ip} "source /etc/profile"

done